package org.budo.support.java.net.util;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

/**
 * @author lmw
 */
public class SocketUtil {
    public static void close(Socket socket) {
        try {
            socket.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public static Socket newSocket(String host, int port) {
        try {
            return new Socket(host, port);
        } catch (IOException e) {
            throw new IllegalStateException("#24 new Socket error, host=" + host + ", port=" + port + ", e=" + e, e);
        }
    }

    public static OutputStream getOutputStream(Socket socket) {
        try {
            return socket.getOutputStream();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public static InputStream getInputStream(Socket socket) {
        try {
            return socket.getInputStream();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}